import Toast from '../../../miniprogram_npm/@vant/weapp/toast/toast';
const app = getApp()
const api = app.globalData.api
Page({

  /**
   * 页面的初始数据
   */
  data: {
    active:0,
    time:'',
    timer:'',
    show:false,
    menu:[],
    weeArray:['日','一','二','三','四','五','六'],
    dayArr:[],
    date_title:'',
    selected_Date:'',
    selected_month:'',
    formate_selected_month:'',
    formate_selected_date:'',
    today:'',//当前选中的第几个日期
  },

  /**新增访客计划 */
  edit(){
    wx.navigateTo({
      url: '../visitPlanEdit/visitPlanEdit?date='+this.data.formate_selected_date,
    })
  },
  detail(e){
    wx.navigateTo({
      url: '../visitPlanInfo/visitPlanInfo?id='+e.currentTarget.dataset.id
    })
  },
  /***关闭弹出层 */
  onClose(e){
    this.requestData();
    this.setData({
      show:false
    })
  },
  /**tabar切换 */
  onChange(event){
    let index = event.detail;
    this.setData({
      active: index
    });
    this.requestData();
  },
 
  chooseDate(e){
    this.setData({
      formate_selected_date:e.currentTarget.dataset.date
    })
    this.requestData();
  },
  changeMonth(e){
    let type = e.currentTarget.dataset.type;
    let month = this.data.formate_selected_month;
  
    if(type=='pre'){
      month=api.getPreMonth(api.formatDateCRM('Y/m',month));
    }else if(type=='next'){
      month=api.getNextMonth(api.formatDateCRM('Y/m',month));
    }
    this.setData({
      formate_selected_date:month+'-01'
    })
    this.requestData();
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
  },

  /**请求数据 */
  requestData(){
    let that = this;
    let para = {
      date:that.data.formate_selected_date,
    }
    api.curlPost('?cla=clientAppClass&fun=visitPlanList',para).then((res)=>{
      that.setData({
        date_title:res.data.result.formatDate,
        state:res.data.result.state,
        dayArr:res.data.calendar.list,
        selected_month:api.formatDateCRM('Y年m月',res.data.calendar.month),
        formate_selected_month:api.rowTocol(res.data.calendar.month),
        formate_selected_date:res.data.calendar.date,
        list:res.data.result
      })
    })
  },

  
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.requestData();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})